package com.dyb.recuitment.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.common.Result;
import com.dyb.recuitment.entity.Resume;
import com.dyb.recuitment.entity.Shield;
import com.dyb.recuitment.entity.User;
import com.dyb.recuitment.service.IResumeService;
import com.dyb.recuitment.service.IUserLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 简历表 前端控制器
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-15
 */

@Api(tags = "简历模块管理(Resume)")
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private IResumeService resumeService;

    @Autowired
    private IUserLogService userLogService;

    @ApiOperation(value = "添加简历", notes = "通过模块、标题、内容、起止时间、备注、创建人添加简历模块 " +
            "{\"name\":\"\",\"title\":\"\",\"content\":\"\",\"startDate\":\"2022-02-02\",\"finalDate\":\"2022-02-02\",\"remark\":\"\",\"createBy\":1}")
    @ApiImplicitParam(name = "resume", value = "Resume类")
    @PostMapping("/add")
    public Object add(@RequestBody Resume resume) {
        Object data = null;
        try {
            data = resumeService.add(resume);
            if (data == null || (int) data == 0) {
                return Result.failure(data, "添加失败!");
            }
            return Result.success(data, "添加成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "简历模块详情", notes = "通过ID查询简历模块详情 {\"id\":1}")
    @ApiImplicitParam(name = "resume", value = "Resume类")
    @PostMapping("/selectById")
    public Object selectById(@RequestBody Resume resume) {
        Object data = null;
        try {
            data = resumeService.getById(resume);
            if (data == null) {
                return Result.warning(data, "简历模块为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "个人简历", notes = "通过创建人查询用户个人简历 {\"createBy\":1}")
    @ApiImplicitParam(name = "resume", value = "Resume类")
    @PostMapping("/selectByCreateBy")
    public Object selectByCreateBy(@RequestBody Resume resume) {
        Object data = null;
        try {
            data = resumeService.selectByCreateBy(resume);
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "简历模块为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "修改简历模块", notes = "修改简历模块 {\"\":\"\",\"id\":1}")
    @ApiImplicitParam(name = "resume", value = "Resume类")
    @PostMapping("/update")
    public Object update(@RequestBody Resume resume) {
        Object data = null;
        try {
            data = resumeService.update(resume);
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "修改失败!");
            }
            return Result.success(data, "修改成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "删除简历模块", notes = "通过ID删除简历模块" +
            "{\"id\":1}")
    @ApiImplicitParam(name = "resume", value = "Resume类")
    @PostMapping("/delete")
    public Object delete(@RequestBody Resume resume) {
        Object data = null;
        try {
            data = resumeService.delete(resume);
//            userLogService.add(new UserLog(resume.getUserId(), "删除简历模块"));
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "删除失败!");
            }
            return Result.success(data, "删除成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询所有简历模块", notes = "查询所有简历模块")
    @GetMapping("/selectAllResume")
    public Object selectAllResume() {
        Object data = null;
        try {
            data = resumeService.selectAllResume();
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "简历模块为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

}
